package cn.edu.scau.cmi.yangchunmei.client;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class climent {
public static void main(String[] args) throws ClassNotFoundException, SQLException {

		Class.forName("com.mysql.jdbc.Driver");
	String url = "jdbc:mysql://localhost:3306/jsp";
	String username = "root";
	String password = "root";
	Connection conn = DriverManager.getConnection(url, username,password);
	//String insertSql ="insert into tb_student(age,sex,name,id) values('1','0','zhangshan','3')";
	//Statement ps = conn.prepareStatement(insertSql);
	
	/*String insertSqlDynamic = "insert into tb_student(age,sex,name,id) values(?,?,?,?)";
	PreparedStatement dps = conn.prepareStatement(insertSqlDynamic);
	dps.setInt(1, 22);
	dps.setInt(2,1);
	dps.setString(3, "zhangxiaoli");
	dps.setInt(4,5);
	
	//ps.executeUpdate(insertSql);
	dps.execute();
	System.out.println("ok");*/
	
	 String selectSql="select * from tb_student";
	 PreparedStatement ds = conn.prepareStatement(selectSql);
	 ResultSet rs = ds.executeQuery(selectSql);
	 while(rs.next()) {
	 System.out.println("id:"+rs.getInt(1)+", name:"+rs.getString(2)+", sex:"+rs.getInt(3)+",age:"+rs.getInt(4));
	 }
}
}

